package com.cqu.apptest.controller;

import com.cqu.apptest.service.FileService;
import com.cqu.springmvc.annotation.Autowired;
import com.cqu.springmvc.annotation.Controller;
import com.cqu.springmvc.annotation.RequestMapping;
import com.cqu.springmvc.annotation.RequestParm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;
import java.util.List;

@Controller
public class FileController {

    @Autowired
    FileService fileService;

    @RequestMapping("/file/upload")
    public String  fileUpload(HttpServletRequest request, @RequestParm("files") List<Part> files){
        //判断文件集合是否为空
        if(files!=null & files.size()>0){
            for (Part file : files){
                //上传文件
                String msg = fileService.uploadFile(file,request);
                request.setAttribute("fileMessage",msg);
            }
        }
        return "forward:/upload_finish.jsp";
    }


}